//用户使用的浏览器版本数据
var IE_data;
//身份证头像base64数据
var Previewdata = "";
// 摄像头
var DevIndex;
//纠偏 默认关闭
var rectifying = "0";
//模式
var ModelNumIndex = "0";
//画质
var QualityNumindex = "0";
// 放大的值
var corp = 1;
// 视频录制状态
var Start_Video, Pause_Video, Stop_Video;
// 数组存储拍照图片
let Arraydata = [];
// 卡类型
var IDCard = 1;
// 自动拍照
var movedetec = 1;


window.onload = function () {
    IE_data = IEVersion();
    if (IE_data == "Chrome" || IE_data == "edge" || IE_data == "Firefox") {
        var imgdata = document.getElementById("OCX");
        imgdata.style.display = "none";
        imgdata.style.visibility = "hidden";
    } else {
        var imgdata = document.getElementById("Chrome");
        imgdata.style.display = "none";
        imgdata.style.visibility = "hidden";

    }
    if (IE_data <= 7) {
        if (!window.JSON) {
            window.JSON = {
                parse: function (jsonStr) {
                    return eval('(' + jsonStr + ')');
                }
            }
        }
    }
    document.getElementById('device').add(new Option("主摄像头"));
    document.getElementById('device').add(new Option("副摄像头1"));
    document.getElementById('device').add(new Option("副摄像头2"));
    document.getElementById('device').selectedIndex = 0;
    Getdevice();
}
//判断浏览器
function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器 
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器 
    var isChrome = userAgent.indexOf("Chrome") > -1 && !isIE; //判断是否IE的Chrome浏览器 
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    var Firefox = userAgent.indexOf("Firefox") > -1 && !isIE;

    if (isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if (fIEVersion == 7) {
            return 7;
        } else if (fIEVersion == 8) {
            return 8;
        } else if (fIEVersion == 9) {
            return 9;
        } else if (fIEVersion == 10) {
            return 10;
        } else {
            return 6;//IE版本<=7
        }
    } else if (isEdge) {
        return 'edge';//edge
    } else if (isIE11) {
        return 11; //IE11 
    } else if (isChrome) {
        return 'Chrome'  //Chrome
    } else if (Firefox) {
        return 'Firefox'  //Firefox
    } else {
        return -1;//不是ie浏览器
    }
}

//设置DPI
function SetDPI() {
    var DPFnumber = document.getElementById("DPFinput").value;
    if (DPFnumber !== "") {
        var data = {
            "dpiflag": "1",    // 生效开关，0：不设置, 1：设置
            "xdpi": DPFnumber,       // X dpi值，取值范围：[96~1200]
            "ydpi": DPFnumber      // Y dpi值，取值范围：[96~1200]
        }
        var url = "http://127.0.0.1:38088/device=setdpi";
        Ajax("post", url, JSON.stringify(data), function gettingData(res) {
            if (res.code === "0") {
                log("DPI设置成功:" + DPFnumber);

            } else {
                log("DPI设置失败");
            }
        }
        )

    } else {
        log("请输入需要设置的DPI数值")
    }

}


//打开摄像头
function OpenCamera() {
    log("当前浏览器为:" + IE_data);
    DevIndex = document.getElementById('device').selectedIndex;
     if (IE_data == "Chrome" || IE_data == "edge" || IE_data == "Firefox") {
		// if (1) {
        var random = Math.random(); //创建随机数
        document.getElementById("chrome_img").src = "";
        document.getElementById("chrome_img").src = "http://127.0.0.1:38088/video=stream&camidx=" + DevIndex + "?" + random;
    } else {
        showVideoOcx.StartPreview(DevIndex);
    }

}

// 切换摄像头
function selectDevice() {
    OpenCamera();
    var Gettion = setTimeout(function () {
        GetResolution();
        clearTimeout(Gettion);
    }, 2000);
}

//关闭摄像头
function CloseCamera() {
    DevIndex = document.getElementById('device').selectedIndex;
    if (IE_data == "Chrome" || IE_data == "edge" || IE_data == "Firefox") {
        var data = {
            camidx: JSON.stringify(DevIndex)
        };
        var url = "http://127.0.0.1:38088/video=close";
        Ajax("post", url, JSON.stringify(data), function gettingData(res) {
            if (res.code === "0") {
                document.getElementById("chrome_img").src = "";
                log("摄像头关闭成功");

            } else {
                log("摄像头关闭失败");
            }

        }
        )
    } else {
        if (showVideoOcx.StopPreview()) {
            log("关闭成功")
        } else {
            log("关闭失败")
        }

    }
}

//切换设置分配率 
function selectResolution() {
    DevIndex = document.getElementById('device').selectedIndex;
    var idx = document.getElementById("resolution").selectedIndex
    var indexdata = document.getElementById("resolution").options[idx].text;
    var words = indexdata.split("*");
    log(words[0], words[1]);

    var data = {
        camidx: DevIndex,
        mode: "0",
        width: words[0],
        height: words[1],
    };
    var url = "http://127.0.0.1:38088/device=setresolution";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("分辨率设置成功：" + idx)
            CloseCamera();
            var Gettion = setTimeout(function () {
                OpenCamera();
                clearTimeout(Gettion);
            }, 1500);
        } else {
            log("分辨率设置失败");
        }

    }
    )

}
//获取分配率
function GetResolution() {
    document.getElementById('resolution').innerHTML = "";
    DevIndex = document.getElementById('device').selectedIndex;
    var data = {
        "camidx": JSON.stringify(DevIndex),  // 必选，摄像头，0：主头，1：副头
        "mode": "0"     // 必选，视频模式，0：YUY2（高清），1：MJPG（高速）
    }
    var url = "http://127.0.0.1:38088/device=getresolution";
    Ajax("get", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("分配率获取成功");
            var resolution = document.getElementById("resolution");
            strData = res.data.split("|");
            var addOption = function (select, txt, value, num) {
                select.add(new Option(txt, value), num);
            };
            for (var i = 0; i < strData.length; i++) {
                addOption(resolution, strData[i], i);
            }

        } else {
            log("获取分配率失败");
        }

    }
    )

}
//画质
function Quality(data) {
    QualityNumindex = JSON.stringify(data);
}
//模式
function ModelNum(data) {
    ModelNumIndex = JSON.stringify(data);
}
// 开启关闭裁边
function OpenDeskew() {
    if (rectifying == "0") {
        rectifying = "1";
        OpenCorrect();
    } else {
        rectifying = "0";
        OpenCorrect();
    }
}
function OpenCorrect() {
    var data = {
        "camidx": JSON.stringify(DevIndex),  // 摄像头索引，0：主头；1：副头
        "open": rectifying     // 状态，0：关；1：开
    }
    var url = "http://127.0.0.1:38088/dvideo=cameradeskew";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("纠偏请求成功")

        } else {
            log("纠偏请求失败");
        }

    }
    )
}
//开启自动拍照
function AutoScan() {
    var url = "http://127.0.0.1:38088/video=movedetec"
		
    var data = {
        "movedetecflag": "1",           // 开启自动拍照
        "listpath": "D://httpcamera",   // 图片保存目录
        "filepath": "LT",                // 图片名称前缀
		"bAutoAdjust":1,
        "ColorMode": ModelNumIndex, // 色彩模式，图片保存本地时调用。0：彩色 1：灰色 2：黑白 3：白纸印章 4：去背景色(普通文件) 5:去背景色(身份证)
		"deskew": rectifying,      // 纠偏（主头有效），参数：0:不纠偏；1:纠偏
        "deskewval": 10,       // 纠偏像素值：正常给0，正数时多裁，负数时少裁
    }
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("开启自动拍照成功")
			if(res.data)
			{
				 addImgDiv(res.data);
				 AutoScan();
			}  
        } else {
            log("开启自动拍照失败");
        }

    }
    )

}
//关闭自动拍照
function AutoScanStop() {
    var url = "http://127.0.0.1:38088/video=movedetec"
    var data = {
        "movedetecflag": "0"
    }
		
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("关闭自动拍照成功:" + res.message);

        } else {
            log("关闭自动拍照失败");
        }

    }
    )
}
// 视频预览放大 
function OpenStream() {
    var url = "http://127.0.0.1:38088/stream=zoominout";
    if (corp <= 9) {
        log(corp);
        var data = {
            camidx: JSON.stringify(DevIndex), // 摄像头，0:主头；1:副头
            corp: JSON.stringify(corp), // 放大比例，取值0~9，0：原图，9最大显示
        };

        Ajax("post", url, JSON.stringify(data), function gettingData(res) {
            if (res.code === "0") {
                log("视频预览放大成功");
                corp++;

            } else {
                log("视频预览放大失败");
            }

        }
        )
    } else {
        var data = {
            camidx: JSON.stringify(DevIndex), // 摄像头，0:主头；1:副头
            corp: "0", // 放大比例，取值0~9，0：原图，9最大显示
        };
        Ajax("post", url, JSON.stringify(data), function gettingData(res) {
            if (res.code === "0") {
                log("还原成功");
                corp = 0;
            } else {
                log("还原失败");
            }

        }
        )
    }
}
// 图片旋转，旋转完，拍照哪里可以不需要跟着动态旋转
function Rotation() {
    var data = {
        camidx: JSON.stringify(DevIndex), // 摄像头，0:主头；1:副头
        rotate: "90", // 角度，参数：90、180、270
    };
    var url = "http://127.0.0.1:38088/video=rotate";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("顺时针旋转90°成功");
        } else {
            log("旋转90°失败");
        }

    }
    )
}


// 拍照
function GrabImage() {

    var data = {
        "filepath": "base64",  //1."G://test11.jpg"  指定路径  2."base64" 不保存本地，返回base64  3.""   保存默认路径下
        "rotate": "0",      // 图像旋转角度，90的整数倍，默认："0"
        "deskew": rectifying,      // 纠偏（主头有效），参数：0:不纠偏；1:纠偏
        "deskewval": 10,       // 纠偏像素值：正常给0，正数时多裁，负数时少裁
		"bAutoAdjust":0,       // 自动摆正
        "camidx": 0,      // 摄像头索引，参数：0:主头；1:副头
        "quality": 0, //图片质量，图片保存本地调用。0:默认质量；1:高质量；2:较高质量；3:中质量；4:较低质量；5:低质量
        "ColorMode": 0, // 色彩模式，图片保存本地时调用。0：彩色 1：灰色 2：黑白 3：白纸印章 4：去背景色(普通文件) 5:去背景色(身份证)
        "bIsPrint1to1": "0",   // 1:1打印有一点点偏差 是适用于身份证卡片之类  1:开启;  0 :关闭
		"watermark": {
        "pos": "0",           // 水印在图像中的位置，0:左上；1:右上；2:左下；3:右下；4:中间
        "content": "Hello ", //水印内容，必须utf-8编码，当水印内容为空，将当前时间作为水印
        "transparency": "0",  // 透明度，0~255,0:完全透明；255:不透明
        "fontsize": "100",      // 字体大小，默认：32
        "font": "楷体",          // 字体
        "color": "red"          // 水印颜色，colorname[white,red,green,blue,cyan,magenta,yellow,gray]
    }
    };
    var url = "http://127.0.0.1:38088/video=grabimage";
    Ajax("get", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            console.log(res);
            
             // 如果数组中已经有值，且这个值与传入的 photoBase64 相同，则不进行任何操作
            if (Arraydata.length > 0 && Arraydata[0] === res.photoBase64) {
                return;
            }

            // 如果数组中已经有一张图片，先清空数组
            if (Arraydata.length > 0) {
                Arraydata.length = 0; // 清空数组
            }
            addImgDiv(res.photoBase64);
            // 将新图片添加到数组中
            Arraydata.push(res.photoBase64);
            console.log(Arraydata,'Arraydata')
            window.parent.postMessage(JSON.stringify(res.photoBase64), '*');
            log("拍照成功");
        } else {
            alert("拍照失败");
        }

    }
    )
}
// 监听来自父页面的消息
window.addEventListener('message', function(event) {
    if (event.data === 'getArrayData') {
        // 返回 Arraydata 给父页面
        event.source.postMessage(Arraydata, '*');
    }
});
window.addEventListener('message', function(event) {
    if (event.data === 'destroy') {
        // 在这里执行销毁操作，比如关闭摄像头、停止视频流等
        console.log('Destroying resources...');
        // 示例：关闭摄像头的代码
        // stopCamera();
        // StopVideo()
    }
});

// 图片旋转，旋转完，拍照哪里可以不需要跟着动态旋转
function Rotation() {
    var data = {
        camidx: JSON.stringify(DevIndex), // 摄像头，0:主头；1:副头
        rotate: "90", // 角度，参数：90、180、270
    };
    var url = "http://127.0.0.1:38088/video=rotate";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("顺时针旋转90°成功");
        } else {
            log("旋转90°失败");
        }

    }
    )
}

// 展平拍照
function Flatten() {
    if (DevIndex === 0) {
        var data = {
            filepath: "", // 图片保存位置
            rotate: "0", // 旋转角度
            camidx: JSON.stringify(DevIndex), // 摄像头
            cutpage: rectifying, //
            autoflat: {
                flat: "1",
                leftfilepath: "D://left.jpg",
                rightfilepath: "D://right.jpg",
                removefinger: "1",
                doublepage: "0",
            },
        };
        var url = "http://127.0.0.1:38088/video=autoflat";
        Ajax("get", url, JSON.stringify(data), function gettingData(res) {
            if (res.code === "0") {
                log("展平成功");
                addImgDiv(res.photoBase64);
				if (res.leftphotoBase64)
				{
					addImgDiv(res.leftphotoBase64);
				}
                if (res.rightphotoBase64)
				{
					addImgDiv(res.rightphotoBase64);
				}               
            } else {
                log("展平失败");
            }

        }
        )
    } else {
        alert("请切换到主摄像头,副头不支持展平拍照")
    }


}




//设置录制状态
function SetStartVideoState() {
    var data = ""
    var url = "http://127.0.0.1:38088/get=videorecordstate";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("录像状态获取成功:" + res.state);
        } else {
            log("录像状态获取失败");
        }

    }
    )
}


//视频录制
function StartVideo() {
    var idx = document.getElementById("resolution").selectedIndex
	console.log(document.getElementById("resolution"));
	
    if (DevIndex == "0" ||DevIndex == "1" || DevIndex == "2") {
        // if (words[0] <= "1600" && words[1] <= "1200") {
		if (1) {
            var data = {
                action: "start",
				
                parameter: {
                    camidx: JSON.stringify(DevIndex), // 摄像头索引，默认为：1
					openindex:"0",//0:副头录制 2:主副同时录制
					npos:"4",	//双头录像生效，子窗口显示位置0:左上 1：右上 2:左下 3:右下 4:左右显示(1280*720)
					nchildwidth:"640", //双头录像生效, 子窗口宽，必须小于主窗口宽(npos不等于4生效)
					nchildheight:"480", //双头录像生效, 子窗口高，必须小于主窗口高(npos不等于4生效)
					width: "640", // 视频宽度，默认：640(目前不生效)
                    height: "176", // 视频高度，默认：480(目前不生效)
                    audio: "", // 音频设备名，为空：系统第一个音频设备
                    framerate: "10", // 视频帧率，默认：10
                    filepath: "D:\\视频\\MFVideo00.mp4", //绝对路径，单斜杠 文件保存地址，为空：生成临时文件
                    bit_rate: "400000", // 视频码率，默认：400000
                    watermark: {
                        // 有该参数，将在视频中添加水印
                        pos: "0", // 水印在图像中的位置，0:左上；1:右上；2:左下；3:右下；4:中间
                        content: "abccc水印内容abc", // 水印内容，必须 utf-8编码，为空时只显示时间
                        transparency: "255", // 透明度0~255，0:透明；255:不透明
                        fontsize: "10", // 字体大小，默认：32
                        font: "宋体", // 字体(必填)
                        color: "green", // 水印颜色(必填)，colorname(white,cyan,darkCyan,red,darkRed,magenta,darkMagenta,green,darkGreen,yellow,darkYellow,blue,darkBlue,gray,darkGray,lightGray)
                    },
                },
            };
            var url = "http://127.0.0.1:38088/video=record";
            Ajax("post", url, JSON.stringify(data), function gettingData(res) {
                if (res.code === "0") {
                    log("开始录制" + res.filepath);
                    Start_Video = true;
                } else {
                    log("开始录制失败");
                }
            }
            )
        } else {
            alert("请先切换到200W 以下分配率进行录制")
        }

    } else {
        alert("请先切换到副头")
    }

}

//暂停录制视频
function PauseVideo() {
    var data = {
        action: "pause",
		camidx:"1",
    };
    var url = "http://127.0.0.1:38088/video=record";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("暂停录制成功:" + res.data);
            Pause_Video = true;
        } else {
            log("暂停录制失败:" + res.data);
        }
    }
    );

}

//停止录制视频
function StopVideo() {
    var data = {
        action: "stop",
    };
    var url = "http://127.0.0.1:38088/video=record";
    Ajax("post", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("录制成功:" + res.time);
            Stop_Video = true;
        } else {
            log("录制失败:"+ res.data);
        }
    }
    );

}

// 获取录制视频的base64 
function GetVideoBase64() {
    if (1) {
        var data;
        var url = "http://127.0.0.1:38088/videobase64=get";
        Ajax("post", url, JSON.stringify(data), function gettingData(res) {
            if (res.code === "0") {
                log("获取视频base64成功:" + res.videobase64);
            } else {
                log("录制失败:");
            }
        }
        );
    } else {
        alert("请先1.开始录制视频,2.停止视频,3.在点获取视频base64")
    }
}

//视频base64上传服务器
function UpLoadVideoBase64() {
var data = {
        //shardingUploadUrl: "http://192.168.133.13:9710/upload/shardingUpload",
		//url: "http://172.16.22.72:8889/user/pass/uploadDataTest",
        shardinguploadurl: "http://192.168.133.13:9710/upload/uploadBase64BatchFilter",
		shardingmergeurl: "http://192.168.1.188:9710/upload/uploadBase64BatchFilter",
		//shardingMergeUrl: "http://172.16.22.72:8889/user/pass/uploadDataTest",
		filename: "视频询问",
		filetype: "spxw",
		subdirectory: "/11",
		id: "/1331",
		uploadshardindex:"0",//0：全部上传， 非0：按照当前索引上传
		filepath: "D://视频//MFVideo00.mp4", //视频文件绝对路径，双斜杠
		kbztid:"kbztId",
		shardsize:"10485760",//分片大小1024*1024*10
    };
    var url = "http://127.0.0.1:38088/upload=videotoserver"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("视频上传成功");
        } else {
             log("视频上传失败：" + res.data);
        }
    }
    );
}

//删除视频
function DeleteVideoFile() {
    var data = {
        filepath: "D://视频//11,D://视频//22,D://视频//23",
    };
    var url = "http://127.0.0.1:38088/video=delete";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("删除成功:" + res.data);
            Stop_Video = true;
        } else {
            log("删除失败:"+ res.data);
        }
    }
    );
}


//语音播报
function PalyText() {
    var data = {
        playtext: "语音播报测试test",
		//playtext: "Aこんにちは",
		
    };
    var url = "http://127.0.0.1:38088/voice=broadcast";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("语音播报成功:" + res.data);
            Stop_Video = true;
        } else {
            log("语音播报失败:"+ res.data);
        }
    }
    );
}

//   读取身份证
function ReadIDCard() {

    var data = "";
    var url = "http://127.0.0.1:38088/card=idcard";
    Ajax("POST", url, data, function gettingData(res) {
        if (res.code === "0") {
            Previewdata = res.IDCardInfo.photoBase64;
            var ojbdata = "ReadIDCard <br />返回代码：" + res.code +
                "<br />返回信息：" + res.message +
			    "<br />卡类型：" + res.cardType + //证件类型 1=身份证 2=国外永居证 3=港澳台居住证	4=2023版永居证
                "<br />姓名：" + res.IDCardInfo.name +
				"<br />英文姓名：" + res.IDCardInfo.enname +
				"<br />中文姓名：" + res.IDCardInfo.cnname +
                "<br />性别：" + res.IDCardInfo.sex +
                "<br />民族：" + res.IDCardInfo.nationCode +
                "<br />生日：" + res.IDCardInfo.birthday +
                "<br />地址：" + res.IDCardInfo.address +
                "<br />身份证号：" + res.IDCardInfo.cardID +
                "<br />发卡机构：" + res.IDCardInfo.issueOrgan +
                "<br />有效时间：" + res.IDCardInfo.validStart + "-" + res.IDCardInfo.validEnd +
                "<br />证件UID:" + res.IDCardInfo.strIDUID;
            log(ojbdata)
			addImgDiv(res.IDCardInfo.photoBase64);
			addImgDiv(res.IDCardInfo.photoBase64_Z);
			addImgDiv(res.IDCardInfo.photoBase64_F);
			addImgDiv(res.IDCardInfo.photoBase64_ZF);
            return true;
        } else {
            alert("读取失败")
        }

    }
    )

}

// 推送网页
function PushWeb() {


    var data = { "url": "www.baidu.com" }
    var url = "http://127.0.0.1:38088/pendisplay=pushwebpage";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("成功:" + res.data);
        } else {
            log("推送失败");
        }

    }
    )
}

// 关闭推送网页
function CloseWeb() {
    var data = {}
    var url = " http://127.0.0.1:38088/pendisplay=closewebpage";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("关闭成功:" + res.data);
        } else {
            log("关闭失败");
        }

    }
    )
}
// 网页状态
function WebState() {
    var data = {}
    var url = " http://127.0.0.1:38088/pendisplay=webpagestate";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
			if(res.open === "1")
			{
				log("网页已打开");
			}
			else{
				log("网页已关闭");
			}
            
        } else {
            log("关闭失败");
        }

    }
    )
}

//发送数据
function SendWebData() {
    var data = { 
		"index":"9",
		//"sendData":"http://192.168.29.207:9000/fd-xakb/common/qlywgzs/2023-04-24-14-06-05-B8693303046E41AB89D32EBD92DB8D09/行政案件快速办理告知书1682316365916.pdf",
	
	
	"sendData": "data:image/png;base64哈喽CYII="};
	
    var url = " http://127.0.0.1:38088/push=evaluateinfo";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
		
		if(res.code==="1"){
			 log("发送失败");
		} else {
            log("发送的数据:" + JSON.stringify(res.data));
        } 
    }
    )
}

//获取推送 
function GetWebData() {
    var data = {"index":9};
    var url = " http://127.0.0.1:38088/get=evaluateinfo";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
		
		if(res.code==="1"){
			 log("获取的数据失败");
		} else {
            log("获取的数据:" + JSON.stringify(res.data));
        } 
    }
    )
}

function InitWebData() {
    var data = {}
    var url = " http://127.0.0.1:38088/init=webdata";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") 
		{
            log("网页数据初始化成功:" + res.data);
        } else 
		{
            log("网页数据失败");
        }
    }
    )
}

//条码识别
function OCRbarcode() {
    var data = {
        "time": "20"
    }
    var url = "http://127.0.0.1:38088/barcode=get";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("条码号:" + JSON.stringify(res.data));
        } else {
            log("条码获取失败");
        }

    }
    )
}
// 获取指纹
function GetBiokey() {
    var data = {
        "time": "20"
    }
    var url = "http://127.0.0.1:38088/biokey=get";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            addImgDiv(res.data);
        } else {
            log("指纹获取失败");
        }

    }
    )
}
function Card(CadrdIndex) {
    IDCard = CadrdIndex + 1;
    //  CardIccard();
}
//IC卡
function CardIccard() {
    var data = {
        "iccardtype": IDCard.toString()  // 必选，参数：1：IC卡；2：M1卡；3：MEMORY卡；4：CPU卡(银行卡)；5：SOCIAL社保卡；6:Magnetic 磁条卡 7：SHENZHENTONG 深圳通卡
    }
    var url = " http://127.0.0.1:38088/card=iccard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("读取数据:" + res.toString());
			if(4 == IDCard)
			{				
				 var ojbdata = "ReadICCard <br />返回代码：" + res.code +
                "<br />返回信息：" + res.message +
                "<br />卡号：" + res.bankcardinfo.cardnumber +
				"<br />消费记录：" + res.bankcardinfo.cardrecord +
				"<br />卡轨迹：" + res.bankcardinfo.cardtrack;
				log(ojbdata)
			}
			else if(5 == IDCard)
			{
				var ojbdata = "社保卡 <br />返回代码：" + res.code +
                "<br />返回信息：" + res.message +
                "<br />姓名：" + res.socialcardinfo.name +
				"<br />性别：" + res.socialcardinfo.sex +
				"<br />名族：" + res.socialcardinfo.nation +
				"<br />身份证号：" + res.socialcardinfo.idnumber +
				"<br />出生日期：" + res.socialcardinfo.birthdate +
				"<br />社保卡号：" + res.socialcardinfo.cardnumber +
				"<br />发卡日期：" + res.socialcardinfo.cardissuedate +
				"<br />有效日期：" + res.socialcardinfo.cardeffecdate;
				log(ojbdata)
				
			}
        } else {
            log("IC卡号获取失败");
        }

    }
    )
}
//评价
function OpenEvaluator() {
    var data = ""
    var url = "http://127.0.0.1:38088/sign=showevaluator"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("评价窗口弹出成功");
        } else {
            log("评价窗口弹出失败");
        }

    }
    )
}

//评价结构
function EvaluatorData() {
    var data = ""
    var url = "http://127.0.0.1:38088/sign=getevaluatorresult"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("评价结果:" + res.result);
        } else {
            log("获取数据错误");
        }

    }
    );
}

//关闭评价
function CloseEvaluator() {
    var data = ""
    var url = "http://127.0.0.1:38088/sign=closeevaluator"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("关闭评价窗口成功");
        } else {
            log("关闭评价窗口失败");
        }

    }
    );
}

//弹出签字窗口  
function OpenSign() {
    var data = {
		"pos": {
            "top": "0", //top + height = 760
            "left": "0",
            "width": "1280",
            "height": "800",
			"ButtonOKBKColor": "102,153,204",
            "ButtonClearBKColor": "255,0,0"
        },
        "remark": "开始签名"
    }
    var url = " http://127.0.0.1:38088/serialport=sign"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("签字框弹出成功");
        } else {
            log("签字框弹出失败");
        }

    }
    );
}

//关闭签字窗口   
function IsSignExist() {
    var data = ""
    var url = " http://127.0.0.1:38088/sign=exist"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("签名窗口已打开");
        } else {
            log("签名窗口未打开");
        }

    }
    );
}


//关闭签字窗口   
function CloseSign() {
    var data = ""
    var url = " http://127.0.0.1:38088/serialport=close"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("关闭评价窗口成功");
        } else {
            log("关闭评价窗口失败");
        }

    }
    );
}

//获取签字图片 
function GetSign() {
    var data = {	
		"mainwindow": 1,
	};
    var url = "http://127.0.0.1:38088/pendisplay=getsigndata"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("签字图片base64:" + res.data);
            addImgDiv(res.data);
        } else {
            log("获取签字图片失败");
        }

    }
    );
}


// 获取密钥
function GetKey() {
    var data = ""
    var url = "http://127.0.0.1:38088/softkey=check"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("密钥值:" + res.data);
        } else {
            log("获取密钥");
        }

    }
    );
}

// 获取当前分辨率索引号
function GetResolutionIndex() {
    var data = ""
    var url = "http://127.0.0.1:38088/device=getcurrentresolutionindex"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("分辨率索引号:" + res.index);
        } else {
            log("分辨率索引号获取失败");
        }

    }
    );
}

//获取摄像头打开状态
function GetCamOpenState() {
	
	DevIndex = document.getElementById('device').selectedIndex;
    var data = {
        "index": DevIndex
    }
    var url = "http://127.0.0.1:38088/camera=state";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("摄像头:" + JSON.stringify(res.index) + JSON.stringify(res.state));
        } else {
            log("摄像头:" + JSON.stringify(res.index) + JSON.stringify(res.state));
        }
    }
    )
}


//二寸照
function GrabImageTwoinchPhoto() {	
    var data = "";
    var url = "http://127.0.0.1:38088/twoinchphoto";
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("二寸照获取成功:" + res.data);
			addImgDiv(res.data);
        } else {
            log("二寸照获取失败");
        }
    }
    )
}


// 开始签名
function WindowsSignStart() {
    var data = {
			"top": "0", //top + height = 760
            "left": "0",
            "width": "1920",
            "height": "1080",
			"OKColor": "255,0,0",
            "ReSignColor": "0,128,255",
			"showTitle": "签名提示:请在签字区域进行签字",
			"savePath": "C:\\签名文件\\windowsSign.jpg",
			"mainsavepath": "C:\\签名文件\\windowsSign.jpg",
			"showMain": 1,
	};
    var url = "http://127.0.0.1:38088/windows=signstart"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("签名窗口打开成功");
        } else {
             log("签名窗口打开失败:" + res.data);
        }
    }
    );
}

// 获取签名base64
function WindowsSignGet() {
    var data = {
		"mainwindow": 1,		
	};
    var url = "http://127.0.0.1:38088/windows=getsign"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
         if (res.code === "0") {
            log("获取签名base64:" + res.base64);
			addImgDiv(res.base64);
        } else {
             log("获取签名base64失败:" + res.data);
        }
    }
    );
}

//关闭签名窗口
function WindowsSignClose() {
    var data = ""
    var url = "http://127.0.0.1:38088/windows=closesign"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("关闭签名窗口成功");
        } else {
             log("关闭签名窗口失败" + res.data);
        }
    }
    );
}

//关闭签名窗口
function ZZDevCountCheck() {
    var data = ""
    var url = "http://127.0.0.1:38088/check=cameracount"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("设备个数:" + res.count);
        } else {
             log("获取设备个数失败" + res.data);
        }
    }
    );
}


		
	

function SetScreenCLONEMode() {
        var data = {
        "mode": 0 //0：扩展模式 1：复制模式
    }
    var url = "http://127.0.0.1:38088/setscreen=externclone"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("设置扩展屏成功");
        } else {
             log("设置扩展屏成功" + res.data);
        }
    }
    );
}
function SetScreenEXTENDMode() {
        var data = {
        "mode": 1 //0：扩展模式 1：复制模式
    }
    var url = "http://127.0.0.1:38088/setscreen=externclone"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("设置扩展屏成功");
        } else {
             log("设置扩展屏成功" + res.data);
        }
    }
    );
}

function ShowKeyBoard() {
        var data = ""
    var url = "http://127.0.0.1:38088/show=keyboard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("显示键盘成功");
        } else {
             log("显示键盘失败" + res.data);
        }
    }
    );
}
function CloseKeyBoard() {
        var data = ""
    var url = "http://127.0.0.1:38088/close=keyboard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("关闭键盘成功");
        } else {
             log("关闭键盘失败" + res.data);
        }
    }
    );
}

//删除单个文件或文件夹
function DeleteFileOrDir() {
	var data = {
		 "deletefilepath":"D:\\视频\\1.jpg" //文件或文件夹绝对路径（单个文件或目录）
	}
    var url = "http://127.0.0.1:38088/delete=jpgordirectory"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("删除文件成功");
        } else {
             log("删除文件失败");
        }
    }
    );
}

//读身份证(柒星)
function ReadIDCardQiXin() {
	var data = {}
    var url = "http://127.0.0.1:38088/qixin=readidcard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("读取身份证成功");
			var ojbdata = "ReadIDCard <br />返回代码：" + res.code +
                "<br />返回信息：" + res.message +
                "<br />姓名：" + res.IDCardInfo.name +
				"<br />英文姓名：" + res.IDCardInfo.enname +
				"<br />中文姓名：" + res.IDCardInfo.cnname +
                "<br />性别：" + res.IDCardInfo.sex +
                "<br />民族：" + res.IDCardInfo.nation +
                "<br />生日：" + res.IDCardInfo.birthday +
                "<br />地址：" + res.IDCardInfo.address +
                "<br />身份证号：" + res.IDCardInfo.cardID +
                "<br />发卡机构：" + res.IDCardInfo.issueOrgan +
                "<br />有效时间：" + res.IDCardInfo.validStart + "-" + res.IDCardInfo.validEnd +
                "<br />证件UID:" + res.IDCardInfo.strIDUID;
            log(ojbdata)
			addImgDiv(res.IDCardInfo.headBase64);
        } else {
             log("读书身份证失败");
        }
    }
    );
}
//读银行卡
function ReadBankCardQiXin() {
	var data = {
		 "cardtype":"0" //0:接触 1:非接触
	}
    var url = "http://127.0.0.1:38088/qixin=readbankcard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("读取银行卡成功");
			 var ojbdata = "银行卡号：" + res.bankcardno;
            log(ojbdata)
			
        } else {
             log("读取银行卡失败");
        }
    }
    );
}

//社保卡
function ReadSSCardCardQiXin() {
	var data = {}
    var url = "http://127.0.0.1:38088/qixin=readsscard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("读取社保卡成功");
			     var ojbdata = "社保卡读取 <br />返回代码：" + res.code +
                "<br />返回信息：" + res.message +
                "<br />姓名：" + res.SSCardInfo.name +
                "<br />性别：" + res.SSCardInfo.sex +
                "<br />民族：" + res.SSCardInfo.nation +
				"<br />卡号：" + res.SSCardInfo.sscardnum +
                "<br />社会保障卡号:" + res.SSCardInfo.ssnum;
            log(ojbdata)
        } else {
             log("读取社保卡失败");
        }
    }
    );
}

//磁条卡
function ReadMagneticCardQiXin() {
	var data = {}
    var url = "http://127.0.0.1:38088/qixin=readmaaneticcard"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("读取磁条卡成功");
			     var ojbdata = "磁条卡读取 <br />返回代码：" + res.code +
                "<br />返回信息：" + res.message +
                "<br />磁条卡：" + res.magneticcard;
            log(ojbdata)
        } else {
             log("读取磁条卡失败");
        }
    }
    );
}



function QinXiDuSet() {
	var data = {
		 "imagelev":"2" //0:清晰 1:模糊 2:非常模糊
	}
    var url = "http://127.0.0.1:38088/qingxidu=set"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
            log("设置清晰度成功");
        } else {
             log("设置清晰度失败");
        }
    }
    );
}

//获取心跳
function GetHeartBeat() {
	 var data = ""
    var url = "http://127.0.0.1:38088/get=heartbeat"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
             log("获取心跳成功" + res.data);
        } else {
             log("删获取心跳失败");
        }
    }
    );
}


//显示预览窗口
function ShowPreViewWindow() {
	DevIndex = document.getElementById('device').selectedIndex;
    var data = {
        "index": DevIndex
    }
    var url = "http://127.0.0.1:38088/show=previewwindow"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
             log("预览窗口显示成功" + res.data);
        } else {
             log("预览窗口显示失败");
        }
    }
    );
}

//关闭预览窗口
function ClosePreViewWindow() {
	var data = ""
    var url = "http://127.0.0.1:38088/close=previewwindow"
    Ajax("POST", url, JSON.stringify(data), function gettingData(res) {
        if (res.code === "0") {
             log("关闭预览窗口显示成功" + res.data);
        } else {
             log("关闭预览窗口显示失败");
        }
    }
    );
}
